package org.liaohailong.library.widget

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

/**
 * Author: liaohailong
 * Date: 2019/3/11
 * Time: 23:12
 * Description:
 **/
class CustomLayoutManager : RecyclerView.LayoutManager() {

    override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
        return RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
    }

    override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) {
        super.onLayoutChildren(recycler, state)
        if (state!!.isPreLayout) return
        recycler?.let {
            detachAndScrapAttachedViews(it)
            val scrap = it.getViewForPosition(0)
            measureChildWithMargins(scrap, 0, 0)
            layoutDecoratedWithMargins(scrap, 0, 0, 0, 0)
        }
    }

}